'use strict';
'require view';
'require fs';
'require rpc';
'require form';
'require validation';
'require ui';
var callLte1InfoDump = rpc.declare({
	object: 'sihan.lte',
	method: 'lte1_info',
	expect: {}
});
var callLte1InitDump = rpc.declare({
	object: 'sihan.lte',
	method: 'lte1_init',
	params: ['apn','nat','usbnet'],
	expect: {}
});
var callLte2InfoDump = rpc.declare({
	object: 'sihan.lte',
	method: 'lte2_info',
	expect: {}
});
var callLte2BaseDump = rpc.declare({
	object: 'sihan.lte',
	method: 'lte2_base',
	expect: {}
});

var formData={};
return view.extend({
	load: function() {
		return Promise.all([callLte1InfoDump()]);
	},
	onClick: function(apn, nat, usbnet){
		
		var res = Promise.all([callLte1InitDump(apn, nat, usbnet)]);
		console.log(res);
	},
	render: function(data) {
		var table1 = E('table', {
			'class': 'table assoclist',
			'id': 'wifi_assoclist_table'
		}, [E('tr', {
			'class': 'tr table-titles'
		}, [E('th', {
			'class': 'th nowrap'
		}, _('参数名称')), E('th', {
			'class': 'th hide-xs'
		}, _('参数值')), E('th', {
			'class': 'th'
		}, _('参数名称')), E('th', {
			'class': 'th'
		}, _('参数值')), E('th', {
			'class': 'th'
		}, _('参数名称')), E('th', {
			'class': 'th'
		}, _('参数值'))])]);

		// LTE1
		var lte1Info = data[0];
		var lte1Data = [
			{name1: '模块品牌', val1: lte1Info.cgmi, name2: '模块型号', val2:lte1Info.cgmm, name3: '模块SN', val3: lte1Info.gsn}, 
			{name1: 'QCCID', val1:lte1Info.qccid, name2: '信号强度', val2: lte1Info.signalPower, name3: '信号质量', val3:lte1Info.signalQuality},
			{name1: '模块状态', val1: lte1Info.state, name2: '运营商', val2:lte1Info.RAT, name3: 'TDD', val3: lte1Info.is_tdd}, 
			{name1: 'MCC', val1:lte1Info.MCC, name2: 'MNC', val2: lte1Info.MNC, name3: '小区ID', val3:lte1Info.cellID},
			{name1: '工作频率', val1: lte1Info.EARFCN+"MHz", name2: '下行带宽', val2:lte1Info.DL_bandwidth+"MHz", name3: '上行带宽', val3: lte1Info.UL_bandwidth+"MHz"}, 
			{name1: 'freq_band_ind', val1: lte1Info.freq_band_ind, name2: 'TAC', val2: lte1Info.TAC, name3: 'PCI', val3:lte1Info.PCI},
			{name1: 'RSRP', val1: lte1Info.RSRP, name2: 'RSRQ', val2:lte1Info.RSRQ, name3: 'RSSI', val3: lte1Info.RSSI}, 
			{name1: 'SINR', val1:lte1Info.SINR, name2: 'srxlev', val2: lte1Info.srxlev, name3: '注册情况', val3: lte1Info.creg},
			{name1: '模块地址', val1:lte1Info.cgpaddr, name2: '发送数据', val2: lte1Info.bytes_sent, name3: '接收数据', val3: lte1Info.bytes_recv},
		];

		cbi_update_table(table1, lte1Data.map(L.bind(function(s) {
			var rows = [s.name1, s.val1, s.name2, s.val2, s.name3, s.val3];
			return rows;
		}, this)), E('em', _('There are no active leases')));
		var lte1Status = E('div',{},[
			E('h2', 'Lte1状态:'), 
			table1,
			E('h2', 'Lte1配置:'),
			E('input', {
				'id': 'apn',
				'type': 'text',
				'style': 'margin-right:15px',
				'placeholder': 'apn',
			}),E('select', {
				'style': 'margin-right:15px',
				'id':'nat'
			},[
				E('option',{'value':'1'},'ECM'),
				E('option',{'value':'2'},'MBIM'),
				E('option',{'value':'3'},'RNDIS'),
				E('option',{'value':'5'},'NCM')
			]),E('select', {
				'style': 'margin-right:15px',
				'id':'usbnet'
			},[
				E('option',{'value':'0'},'网卡模式'),
				E('option',{'value':'1'},'路由模式'),
				E('option',{'value':'2'},'网桥模式'),
			]), E('span', {
				'class': 'control-group'
			},
			[E('button', {
				'class': 'cbi-button cbi-button-apply',
				'click': ui.createHandlerFn(this,
				function() {
					var apn = document.querySelector('input[id="apn"]').value;
					var nat = document.querySelector('select[id="nat"]').value;
					var usbnet = document.querySelector('select[id="usbnet"]').value;
					let nat_int = parseInt(nat); // 59
					let usbnet_int = parseInt(usbnet);
					return this.onClick(apn, nat_int, usbnet_int);
				}),
			},
			_('保存配置')), ' '])
		]);

		
		// LTE2
		/*
		var lte2Base = data[2];
		var lte2Info = data[3];
		var table2 = E('table', {
			'class': 'table assoclist',
			'id': 'wifi_assoclist_table'
		}, [E('tr', {
			'class': 'tr table-titles'
		}, [E('th', {
			'class': 'th nowrap'
		}, _('参数名称')), E('th', {
			'class': 'th hide-xs'
		}, _('参数值')), E('th', {
			'class': 'th'
		}, _('参数名称')), E('th', {
			'class': 'th'
		}, _('参数值')), E('th', {
			'class': 'th'
		}, _('参数名称')), E('th', {
			'class': 'th'
		}, _('参数值'))])]);
		var lte2Data = [
			{name1: '模块品牌', val1: lte2Base.cgmi, name2: '模块型号', val2:lte2Base.cgmm, name3: '模块SN', val3: lte2Base.gsn}, 
			{name1: 'QCCID', val1:lte2Base.qccid, name2: '信号强度', val2: lte2Info.signalPower, name3: '信号质量', val3:lte2Info.signalQuality},
			{name1: '模块状态', val1: lte2Info.state, name2: '运营商', val2:lte2Info.RAT, name3: 'TDD', val3: lte2Info.is_tdd}, 
			{name1: 'MCC', val1:lte2Info.MCC, name2: 'MNC', val2: lte2Info.MNC, name3: '小区ID', val3:lte2Info.cellID},
			{name1: '工作频率', val1: lte2Info.EARFCN+"MHz", name2: '下行带宽', val2:lte2Info.DL_bandwidth+"MHz", name3: '上行带宽', val3: lte2Info.UL_bandwidth+"MHz"}, 
			{name1: 'freq_band_ind', val1: lte2Info.freq_band_ind, name2: 'TAC', val2: lte2Info.TAC, name3: 'PCI', val3:lte2Info.PCI},
			{name1: 'RSRP', val1: lte2Info.RSRP, name2: 'RSRQ', val2:lte2Info.RSRQ, name3: 'RSSI', val3: lte2Info.RSSI}, 
			{name1: 'SINR', val1:lte2Info.SINR, name2: 'srxlev', val2: lte2Info.srxlev, name3: '注册情况', val3: lte1Info.creg},
			{name1: '模块地址', val1:lte2Info.cgpaddr, name2: '发送数据', val2: lte2Info.bytes_sent, name3: '接收数据', val3: lte2Info.bytes_recv},
		];

		cbi_update_table(table2, lte2Data.map(L.bind(function(s) {
			var rows = [s.name1, s.val1, s.name2, s.val2, s.name3, s.val3];
			return rows;
		}, this)), E('em', _('There are no active leases')));
		var lte2Status = E([
			E('h2', 'Lte2状态:'), 
			table2
		]);
		*/
		return E('div',{}, [lte1Status]);
	},
	handleSaveApply: null,
	handleSave: null,
	handleReset: null
});